﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;

namespace DiPlaner.Profile
{
    public class DBData : INotifyPropertyChanged
    {
        /*
        
        #region Variables

        public int Index;
        public bool Ready;
        public BotProfile Bot;
        private string _workPlan;
        public string WorkPlan
        {
            get { return _workPlan; }
            set
            {
                _workPlan = value;
                WorkPlanDetail = new BotSchedule
                                     {
                                         unlim = value == "unlim",
                                         workTime = ParsePlanTime(value, 'w'),
                                         delayTime = ParsePlanTime(value, 'd'),
                                         idleTime = ParsePlanTime(value, 'i'),
                                         repeatCount = (int)ParsePlanTime(value, 'r').TotalHours
                                     };
            }
        }
        public BotSchedule WorkPlanDetail;
        public DateTime StartDate;

        static TimeSpan ParsePlanTime(string value, char flag)
        {
            return (from wt in value.Split(',')
                    where wt[1] == flag
                    let h = flag == 'r' ? wt.Substring(1) : wt.Substring(1, wt.IndexOf(':') - 1)
                    let m = flag == 'r' ? "0" : wt.Substring(wt.IndexOf(':') + 1, 2)
                    select new TimeSpan(int.Parse(h), int.Parse(m), 0)).FirstOrDefault();
        }

        public struct BotSchedule
        {
            public bool unlim;
            public TimeSpan workTime;
            public TimeSpan delayTime;
            public TimeSpan idleTime;
            public int repeatCount;
        }

        public struct BotProfile
        {
            public string d3_path;
            public string bnet;
            public string pass;

            public string db_path;
            public string db_key;
            public string db_routine;

            public Size size;
            public Point pos;

            public BotStatus status;
        }

        public enum BotStatus
        {
            stoped,
            paused,
            running,
            idle,
            crashed
        }
        #endregion

        #region Init

        public D3Data()
        {
            Bot = new BotProfile {status = BotStatus.idle};
            WorkPlan = "unlim";
        }
        #endregion

        #region Runtime functions

        public bool Start()
        {

            return false;
        }

        public void Pause()
        {
            
        }

        public bool Resume()
        {

            return false;
        }

        public void Stop()
        {
            
        }
        #endregion






        //*/
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyChangings(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null) 
                handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
